//
//  HorizontalButton.swift
//  WBSwift
//
//  Created by maker on 2016/11/10.
//  Copyright © 2016年 maker. All rights reserved.
//

import UIKit
/*
 [注意]自定义控件
 1> 一般实现init()或者init(frame: CGRect)方法
 2>required init? 必须实现  如果从 xib 来创建会调用这个方法
 */
class HorizontalButton: UIButton {

    init(imageName:String,selectName:String, title:String ) {
        super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
        setImage(UIImage(named: imageName), for: UIControlState())
        setImage(UIImage(named: selectName), for: .selected)
        setTitle(title, for: UIControlState())
        setTitleColor(UIColor.black, for: UIControlState())
        sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame.origin.x = 0;
        imageView?.frame.origin.x = (titleLabel?.frame.size.width)! + 8
        imageView?.center.y = (titleLabel?.center.y)!
    }

}
